package edu.nf.vrs.admin.controller;

import edu.nf.vrs.admin.vo.PageVO;
import edu.nf.vrs.admin.vo.ResultVO;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * @author Lv
 * @date 2022/4/2
 */
public class BaseController {

    public ResultVO success(){
        ResultVO vo = new ResultVO();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    public <T> ResultVO <T> success(T data){
        ResultVO vo = new ResultVO();
        vo.setData(data);
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    public ResultVO error(int code){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        return vo;
    }

    public ResultVO error(int code,String message){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }

    public <T> ResultVO<List<T>> page(Long total,List<T> list){
        PageVO vo = new PageVO();
        vo.setCount(total);
        vo.setCode(0);
        vo.setData(list);
        return vo;
    }
}
